import {Injectable, InjectionToken, NgModule} from '@angular/core';
import {BrowserModule} from '@angular/platform-browser';
import {RouteReuseStrategy} from '@angular/router';
import {CoreModule} from '@core/core.module';
import {RebirthRouterReuseStrategy} from '@core/route-reuse/route-reuse.service';
import {SharedModule} from '@shared/shared.module';
import {AppRoutingModule} from './app-routing.module';
import {AppComponent} from './app.component';
import {LocationStrategy, HashLocationStrategy, PathLocationStrategy} from "@angular/common";
import {HammerGestureConfig, HAMMER_GESTURE_CONFIG} from '@angular/platform-browser';
import 'hammerjs';
import {SCRIPT_LOADER, ScriptLoader, Scripts} from "@core/script-loader/script-loader";
// import {Scripts, ScriptLoader} from 'ngx-script-loader/script-loader';


declare var Hammer: any;

@Injectable()
export class MyHammerConfig extends HammerGestureConfig {
  buildHammer(element: HTMLElement) {
    const guest = new Hammer(element, {
      touchAction: "pan-y",
    });
    return guest;
  }
}

// export const SCRIPT_LOADER = new InjectionToken('script_loader');

const ScriptStore: Scripts[] = [
  {name: 'basketball_playbook', src: '/assets/js/playbook/basketball.playbook.js'},
  {name: 'echarts', src: '/assets/js/echarts/echarts.common.min.js' }
];

export function scriptLoaderFactory() {
  return new ScriptLoader(ScriptStore)
}

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    CoreModule,
    AppRoutingModule,
    SharedModule,
  ],
  providers: [
    {provide: RouteReuseStrategy, useClass: RebirthRouterReuseStrategy},
    {provide: LocationStrategy, useClass: PathLocationStrategy},
    {provide: HAMMER_GESTURE_CONFIG, useClass: MyHammerConfig},

    {
      provide: SCRIPT_LOADER,
      useFactory: scriptLoaderFactory,
    }
  ],
  bootstrap: [AppComponent]
})
export class AppModule {
}
